package com.henu.art.controller;

import com.henu.art.annotation.IgnoreToken;
import com.henu.art.entity.Teacher;
import com.henu.art.service.Imlp.ExcelServiceImpl;
import com.henu.art.service.TeacherService;
import com.henu.art.util.ExcelExportUtil;
import com.henu.art.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RestController
@RequestMapping("export")
@IgnoreToken
@Tag(name = "导出管理", description = "导出相关的操作接口")
public class ExcelController {

    @Resource
    private ExcelServiceImpl excelService;

    @GetMapping("researchInfo")
    @Operation(summary = "导出科研成果信息", description = "导出用户的科研成果信息表格")
    @ApiResponse(responseCode = "200", description = "导出成功")
    @ApiResponse(responseCode = "500", description = "导出失败")
    public Result<?> exportResearchInfo(HttpServletResponse response) throws Exception {
        excelService.exportResearch(response);
        return Result.ok("导出成功");
    }

    @GetMapping("selectedFields")
    @Operation(summary = "导出选择的字段", description = "根据前端选择的字段导出表格")
    @ApiResponse(responseCode = "200", description = "导出成功")
    @ApiResponse(responseCode = "500", description = "导出失败")
    public Result<?> exportSelectedFields(HttpServletResponse response, @RequestParam String fields) {
        try {
            excelService.exportSelectedFields(response, fields);
            return Result.ok("导出成功");
        } catch (Exception e) {
            return Result.error("导出失败：" + e.getMessage());
        }
    }

    @GetMapping("academicOriginInfo")
    @Operation(summary = "导出学缘信息", description = "导出用户的学缘信息表格")
    @ApiResponse(responseCode = "200", description = "导出成功")
    @ApiResponse(responseCode = "500", description = "导出失败")
    public Result<?> exportAcademicOriginInfo(HttpServletResponse response) throws Exception {
        excelService.exportAcademicOrigin(response, "");
        return Result.ok("导出成功");
    }
}
